import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import {getLoginUserUsingGet, getUserVoByIdUsingGet} from "@/api/userController.ts";

export const useLoginUserStore = defineStore('loginUser', () => {
    const loginUser = ref<any>({
        userName: '未登录',
    })

    // 获取登录用户信息
    async function fetchLoginUser() {
        // todo
        const res = await getLoginUserUsingGet();
        if (res.data.code == 0 && res.data.data){
          loginUser.value = res.data.data;
        }
        // // 模拟登录
        // setTimeout(() => {
        //     setLoginUser({userName: 'admin', id: 1})
        // }, 3000)
    }

    // 设置登录用户
    function setLoginUser(newLoginUser: any) {
        loginUser.value = newLoginUser;
    }


    return { loginUser, setLoginUser, fetchLoginUser }
})
